Start general GtkTreeView unit tests
authorKristian Rietveld <kris@gtk.org>
Thu, 30 Jul 2009 11:54:30 +0000 (13:54 +0200)
committerKristian Rietveld <kris@gtk.org>
Thu, 30 Jul 2009 18:24:31 +0000 (20:24 +0200)
Includes a test case for bug 546005 to start with, logic provided by
Paul Pogonyshev and Bjorn Lindqvist.  In the future, we should maybe
merge treeview-scrolling.c with this one to create one large monolithic
tree view tester.

gtk/tests/Makefile.am
gtk/tests/treeview.c [new file with mode: 0644]

index 4c8ff1f1a6d0a4f57b4c6a6a2ceb5094a3c6a199..541cbc278cfc2ce52a96d72564af11cba81404a6 100644 (file)
@@ -34,6 +34,10 @@ TEST_PROGS                   += treestore
 treestore_SOURCES               = treestore.c
 treestore_LDADD                         = $(progs_ldadd)
 
+TEST_PROGS                     += treeview
+treeview_SOURCES                = treeview.c
+treeview_LDADD                  = $(progs_ldadd)
+
 TEST_PROGS                     += treeview-scrolling
 treeview_scrolling_SOURCES      = treeview-scrolling.c
 treeview_scrolling_LDADD        = $(progs_ldadd)
diff --git a/gtk/tests/treeview.c b/gtk/tests/treeview.c
new file mode 100644 (file)
index 0000000..c64d7ba
--- /dev/null
@@ -0,0 +1,81 @@
+/* Basic GtkTreeView unit tests.
+ * Copyright (C) 2009  Kristian Rietveld  <kris@gtk.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gtk/gtk.h>
+
+static void
+test_bug_546005 (void)
+{
+  GtkTreeIter iter;
+  GtkTreePath *path;
+  GtkTreePath *cursor_path;
+  GtkListStore *list_store;
+  GtkWidget *view;
+
+  /* Tests provided by Bjorn Lindqvist, Paul Pogonyshev */
+  view = gtk_tree_view_new ();
+
+  /* Invalid path on tree view without model */
+  path = gtk_tree_path_new_from_indices (1, -1);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
+                            NULL, FALSE);
+  gtk_tree_path_free (path);
+
+  list_store = gtk_list_store_new (1, G_TYPE_STRING);
+  gtk_tree_view_set_model (GTK_TREE_VIEW (view),
+                           GTK_TREE_MODEL (list_store));
+
+  /* Invalid path on tree view with empty model */
+  path = gtk_tree_path_new_from_indices (1, -1);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
+                            NULL, FALSE);
+  gtk_tree_path_free (path);
+
+  /* Valid path */
+  gtk_list_store_insert_with_values (list_store, &iter, 0,
+                                     0, "hi",
+                                     -1);
+
+  path = gtk_tree_path_new_from_indices (0, -1);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
+                            NULL, FALSE);
+
+  gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &cursor_path, NULL);
+  g_assert (gtk_tree_path_compare (cursor_path, path) == 0);
+
+  gtk_tree_path_free (path);
+  gtk_tree_path_free (cursor_path);
+
+  /* Invalid path on tree view with model */
+  path = gtk_tree_path_new_from_indices (1, -1);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
+                            NULL, FALSE);
+  gtk_tree_path_free (path);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/TreeView/cursor/bug-546005", test_bug_546005);
+
+  return g_test_run ();
+}